package logic

import (
	"context"
	"storage/models"

	"storage/internal/svc"
	"storage/pb/storage"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateFolderLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCreateFolderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateFolderLogic {
	return &CreateFolderLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// CreateFolder 创建文件夹
func (l *CreateFolderLogic) CreateFolder(in *storage.FolderInfo) (*storage.Empty, error) {
	_, err := l.svcCtx.FolderModel.Insert(l.ctx, &models.Folders{
		UserId:     in.UserId,
		FolderName: in.FolderName,
		ParentId:   in.ParentId,
		Status:     in.Status,
	})
	if err != nil {
		return nil, err
	}
	return &storage.Empty{}, nil
}
